/*
 * @Author: 杨光辉(GerhardYang)
 * @Date: 2021-06-06 17:36:24
 * @LastEditors: 杨光辉(GerhardYang)
 * @LastEditTime: 2021-08-09 09:19:52
 * @Description: file content
 * @Copyright: 超图软件华中平台客户中心 (SuperMap Software Co., Ltd. -Central China Platform)
 */
const getRootTreeData = (treedata) => {
  // 格式化图层树数据
  function addScopedSlots(treedata) {
    for (let i = 0; i < treedata.length; i++) {
      let node = treedata[i];
      node.key = node.id;
      node.scopedSlots = { title: "custom" };

      node.checkable == "Y"
        ? (node.checkable = true)
        : (node.checkable = false);

      if (!node.icon) {
        node.icon = "layers";
      }

      if (node.children) {
        addScopedSlots(node.children);
      }

      if (node.mapUrl !== null) {
        node.mapUrl = window.getServiceUrl(
          node.mapUrl,
          window.servicesPorts.iserver
        );
      }
    }
  }

  addScopedSlots(treedata);

  return treedata;
};

const getLeafTreeData = (treedata) => {
  let nodes = [];
  for (let i = 0; i < treedata.length; i++) {
    let node = treedata[i];
    node.key = node.id;
    node.scopedSlots = { title: "custom" };
    node.checkable == "Y" ? (node.checkable = true) : (node.checkable = false);

    node.hasChild !== "1" ? (node.isLeaf = true) : (node.isLeaf = false);

    if (node.mapUrl !== null) {
      node.mapUrl = window.getServiceUrl(
        node.mapUrl,
        window.servicesPorts.iserver
      );
    }
    if (!node.icon) {
      node.icon = "layers";
    }
    nodes.push(node);
  }
  return nodes;
};
export { getRootTreeData, getLeafTreeData };
